/**
 * Author: Dmitry Ustimov
 * Date: 5/13/13
 * Time: 9:52 AM
 */

package com.gmail.dmitryustimov.ms.java7.chain_of_responsibility.mod.example;

public class Demo {

    private static Handler<LogMessage> createLogger() {

        // Build the chain of responsibility

        Handler<LogMessage> stdOutLogger = new StdoutLogger<>(LogLevel.DEBUG);
        Handler<LogMessage> emailLogger = new EmailLogger<>(LogLevel.NOTICE);
        stdOutLogger.setNext(emailLogger);
        Handler<LogMessage> stdErrLogger = new StderrLogger<>(LogLevel.ERROR);
        emailLogger.setNext(stdErrLogger);

        return stdOutLogger;
    }

    public static void main(String[] args) {

        Handler<LogMessage> handler = createLogger();

        LogMessage debugMsg = new LogMessage("Entering function y.", LogLevel.DEBUG);
        LogMessage noticeMsg = new LogMessage("Step1 completed.", LogLevel.NOTICE);
        LogMessage errorMsg = new LogMessage("An error has occurred.", LogLevel.ERROR);

        // Handled by StdoutLogger
        handler.handle(debugMsg);

        // Handled by StdoutLogger and EmailLogger
        handler.handle(noticeMsg);

        // Handled by all three loggers
        handler.handle(errorMsg);
    }
}
